package com.six.firstpage.controller.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.six.core.entity.HeadNav;
import com.six.core.vo.Result;
import com.six.firstpage.service.HeadNavService;
import com.six.firstpage.vo.SearchVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:zzh
 * @create: 2023-02-27 10:49
 * @Description:
 */
@Api(value = "firstpage/api/headnav", tags = {"导航栏前端Api"})
@RestController
@RequestMapping("firstpage/api/headnav")

public class ApiHeadNavController {
    @Autowired
    private HeadNavService headNavService;

    @GetMapping("getAllHeadNav")
    public Result getAllHeadNav(){
        List<HeadNav> allHeadNav = headNavService.getAllHeadNav();
        return new Result(2000,"查询头部导航栏成功",allHeadNav);
    }


    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "SearchVo", name = "searchVo", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("getHeadNavByTitle")
    public Result getHeadNavByTitle(@RequestBody SearchVo searchVo){
        Page<HeadNav> headNavByTitle = headNavService.getHeadNavByTitle(searchVo.getTitle(), searchVo.getStatus(), searchVo.getCurrent(), searchVo.getPageSize());
        return new Result(2000,"查询导航列表成功",headNavByTitle);
    }


    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "HeadNav", name = "headNav", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("addHeadNav")
    public Result addHeadnav(@RequestBody HeadNav headNav){
        Integer i = headNavService.addHeadNav(headNav);
        if (i>0){
            return new Result(2000,"添加导航成功");
        }
        return new Result(2000,"添加导航失败");
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "HeadNav", name = "headNav", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "PUT")
    @PutMapping("updateHeadNav")
    public Result updateHeadNav(@RequestBody HeadNav headNav){
        Integer i = headNavService.updateHeadNav(headNav);
        if (i>0){
            return new Result(2000,"修改导航成功");
        }
        return new Result(2000,"修改导航失败");
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "headId", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("delHeadNav/{headId}")
    public Result delHeadNav(@PathVariable Integer headId){
        Integer i = headNavService.delHeadNav(headId);
        if (i>0){
            return new Result(2000,"删除导航成功");
        }
        return new Result(2000,"删除导航失败");
    }
}
